<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
    <title>Login</title>
</head>
<body>
<script>
    function regist() {
        $.ajax({
            type: 'POST',
            url: "/account/",
            async: false,
            data: {
                "account": user.value,
                "password": pass.value,
                "remember": document.getElementById("remember").checked,
                "area_id":area.value,
                "is_superuser":superuser.checked,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function change() {
        $.ajax({
            type: 'PUT',
            url: "/account/"+uid.value,
            async: false,
            data: {
                "password": upass.value,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function login() {
        $.ajax({
            type: 'POST',
            url: "/login/",
            data: {
                "account": luser.value,
                "password": lpass.value,
                "remember": document.getElementById("remember").checked,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function logout() {
        $.ajax({
            type: 'POST',
            url: "/logout/",
            data: {},
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function showvalues(obj) {
        console.log(obj);
    }

    function deleteuser() {
        $.ajax({
            type: 'DELETE',
            url: "/account/"+did.value,
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function rbunk() {
        $.ajax({
            type: 'POST',
            url: "/bunk/",
            data: {
                "number": bednum.value,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function cbunk() {
        $.ajax({
            type: 'POST',
            url: "/bunk/",
            data: {
                "number": Math.round(Math.random() * 10000),
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }
    function deletebunk() {
        $.ajax({
            type: 'DELETE',
            url: "/bunk/"+bedid.value,
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function ebunk() {
        $.ajax({
            type: 'PUT',
            url: "/bunk/"+ebedid.value,
            data: {
                "number": ebednum.value,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }

    function carea() {
        $.ajax({
            type: 'POST',
            url: "/area/",
            data: {
                "name": aname.value,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }
    function deletearea() {
        $.ajax({
            type: 'DELETE',
            url: "/area/"+areaname.value,
            dataType: "json",
            success: function (data) {
                console.log(data);
            }
        })
    }
</script>
<table>
    <tr>
        <td>
            <p>用户：{{ request.session.username }}</p>
            <p>超管：{{ request.session.issuperuser }}</p>
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="regist()">注册用户</button>
        </td>
        <td>
            用户名：<input type="text" id="user" value="test2">
        </td>
        <td>
            密码：<input type="text" id="pass" value="test1234">
        </td>
        <td>
            病区：<input type="text" id="area" value="内科病区">
        </td>
        <td>
            超级管理：<input id="superuser" type="checkbox" >
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="login()">用户登陆</button>
        </td>
        <td>
            用户名：<input type="text" id="luser" value="test2">
        </td>
        <td>
            密码：<input type="text" id="lpass" value="test1234">
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="change()">修改用户</button>
        </td>
        <td>
            user_id：<input type="text" id="uid" value="{{ request.session.uid }}">
        </td>
        <td>
            密码：<input type="text" id="upass" value="test1234">
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="deleteuser()">删除用户</button>
        </td>
        <td>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uid：<input type="text" id="did" value="{{ request.session.uid }}">
        </td>
    </tr>
    <tr >
        <td colspan="3">
            <button style="width: 100%" onclick="logout()">用户注销</button>
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="rbunk()">增加床位</button>
        </td>
        <td>
            床号：<input type="text" id="bednum" value="123test">
        </td>
        <td>
            <button style="width: 100%;" onclick="cbunk()">随机增加床位</button>
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="deletebunk()">删除床位</button>
        </td>
        <td colspan="2">
            床 id：<input type="text" id="bedid" value="">
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="ebunk()">修改床位</button>
        </td>
        <td>
            床 id：<input type="text" id="ebedid" value="">
        </td>
        <td>
            床号：<input type="text" id="ebednum" value="1234test">
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="carea()">创建病区</button>
        </td>
        <td>
            病区名称：<input type="text" id="aname" value="123test">
        </td>
    </tr>
    <tr>
        <td>
            <button onclick="deletearea()">删除病区</button>
        </td>
        <td colspan="2">
            病区名称：<input type="text" id="areaname" value="">
        </td>
    </tr>
</table>
记住密码<input id="remember" name="remember" type="checkbox" checked="" onclick="showvalues(this)">
</body>
</html>